<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('新增活动商品')" />
    <th:block th:include="include :: select2-css" />
</head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-product-add">
            <div class="form-group">
                <label class="col-sm-3 control-label is-required">商品ID：</label>
                <div class="col-sm-8">
                    <input name="productId" class="form-control" style="width: 450px;" type="text">
                    <button type="button" class="btn btn-success btn-sm" onclick="addProduct()">添加</button>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">活动商品名称：</label>
                <div class="col-sm-8">
                    <input name="name" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">是否为满减商品：</label>
                <div class="col-sm-8">
                    <label class="radio-box"> <input type="radio" name="isRebate" value="1" th:checked="true"/> 是 </label>
                    <label class="radio-box"> <input type="radio" name="isRebate" value="0" /> 否 </label>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">实收金额：</label>
                <div class="col-sm-8">
                    <input name="payment" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">发放数量：</label>
                <div class="col-sm-8">
                    <label class="radio-box"> <input type="radio" name="isCount" value="0" th:checked="true"/> 不限 </label>
                    <label class="radio-box"> <input type="radio" name="isCount" value="1" /> 含数量限制 </label>
                </div>
            </div>
            <div class="form-group count" hidden>
                <label class="col-sm-3 control-label">数量限制：</label>
                <div class="col-sm-8">
                    <input name="count" class="form-control" type="text">
                </div>
            </div>
        </form>
    </div>
    <th:block th:include="include :: footer" />
    <th:block th:include="include :: select2-js" />
    <script type="text/javascript">
        var prefix = ctx + "activity/product"
        $("#form-product-add").validate({
            focusCleanup: true
        });

        $("input[name='isCount']").on('ifChecked', function(event){
            if(this.value==0){
                $('.count').hide();
            }else if (this.value==1){
                $('.count').show();
            }else {
                $('.count').hide();
            }
        });

        function submitHandler() {
            if ($.validate.form()) {
                console.log($('#form-product-add').serialize());
                $.operate.save(prefix + "/add", $('#form-product-add').serialize());
            }
        }

        //选择商品
        function addProduct() {
            let addProductUrl = prefix + "/selectProduct";
            $.modal.open("选择商品", addProductUrl);
        }

    </script>
</body>
</html>